<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表练习</title>
    <link rel="stylesheet" href="../css/bootstrap.css">
    <link rel="stylesheet" href="../css/brandlist.css">
</head>
<body>
    <script src="../../node_modules/vue/dist/vue.js"></script>
    <script src="../../node_modules/dayjs/dayjs.min.js"></script>
    <div id="app">
        <!-- 头部 -->
        <div class="card">
            <div class="card-header">添加项</div>

            <div class="card-body">
                <!-- 添加品牌的表单区域 -->
                <!-- form 表单元素有 submit 事件 .action事件修饰符会导致添加之后会被清除掉添加项dug -->
                <form @submit.prevent="add">
                    <div class="form-row align-items-center">
                        <div class="col-auto">
                            <div class="input-group mb-2">

                                <div class="input-group-prepend">
                                    <div class="input-group-text">品牌名称</div>
                                </div>
                                <!-- v-model.trim="brand" 双向绑定brand并且.trim去除首尾空格 -->
                                <input type="text" class="form-control" placeholder="请输入品牌名称" v-model.trim="brand">
                            </div>
                        </div>
                        <div class="col-auto">
                            <button type="submit" class="btn btn-primary mb-2">添加</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <!-- 表格 -->
        <table class="table table-bordered table-striped table-hover">
            <thead>
                <th>#</th>
                <th>品牌</th>
                <th>状态</th>
                <th>日期</th>
                <th>操作</th>
            </thead>

            <tbody>
                <tr v-for='(item, index) in list' :key="item.id" :title='item.name'>
                    <td>{{index + 1}}</td>
                    <td>{{item.name}}</td>
                    <td>
                        <div class="custom-control custom-switch">
                            <!-- v-model="item.status"双向绑定  :id="'customSwitch1' + index"动态绑定id -->
                            <input type="checkbox" class="custom-control-input" :id="'customSwitch1' + index"
                            v-model="item.status">
                            <!-- 通过双向绑定来控制 v-if="item.status" 来显示与隐藏-->
                            <label class="custom-control-label" :for="'customSwitch1' + index" v-if="item.status">已启用</label>
                            <label class="custom-control-label" :for="'customSwitch1' + index" v-else>已禁用</label>
                        </div>
                    </td>
                    <td>{{item.time | dateFormat}}</td>
                    <td>
                        <a href="javascript:;" @click="remove(item.id)">删除</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <script src="../js/列表添加练习.js"></script>
</body>
</html>